/**
 * @author YinHang
 */
;(function () {
	function Runner(callback, delay) {
		if(!callback || !delay)
			return null;
		this.callback = callback;
		this.delay = delay;
		this.started = false;
	};
	
	Runner.prototype.start = function () {
		if(this.callback && this.delay)
		{
			var host = this;
			function runner() {
				if(host.started)
				{
					var startTime = new Date().getTime();
					host.callback();
					var nextDelay = host.delay - ( new Date().getTime() ) + startTime;
					if(nextDelay <= 0)
						runner();
					else
					{
						setTimeout(runner, nextDelay);	
					}
				}	
			};
			this.started = true;
			runner();
		}
	};
	
	Runner.prototype.stop = function () {
		this.started = false;
	};
	
	GameFramework.register(Runner);
})();
